//type aliases 类型别名
type Plustype = (x: number, y: number) => number
function sum(x: number, y: number): number {
    return x + y
}
const sum2: Plustype = sum

//联合类型
type NameResolver = () => string
type NameOrResolver = string | NameResolver
function getName(n: NameOrResolver): string {
    if (typeof n === 'string') {
        return n
    } else {
        return n()
    }
}

//type assertion 类型断言
function gerLength(input: string | number): number {
    if ((<string>input).length) {
        return (<string>input).length
    } else {
        return input.toString().length
    }
}



